﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace GetData
{
    public class xmlOperate
    {
        /// <summary>
        /// 读取xml文件获取参数信息
        /// </summary>
        /// <returns></returns>
        public jdCongfigModel GetJDModelByXML()
        {
            jdCongfigModel model = new jdCongfigModel();
            try
            {
                string str = System.Environment.CurrentDirectory;
                XmlDocument xdoc = new XmlDocument();
                //相对路径
                xdoc.Load(str+@"\jdUrlConfig.xml");
                //读取节点
                XmlNode xmlNode1 = xdoc.SelectSingleNode("/infos/appkey");
                if (xmlNode1 != null)
                {
                    model.appkey = xmlNode1.InnerText.Trim();
                }
                XmlNode xmlNode2 = xdoc.SelectSingleNode("/infos/appsecret");
                if (xmlNode2 != null)
                {
                    model.appsecret = xmlNode2.InnerText.Trim();
                }
                XmlNode xmlNode3 = xdoc.SelectSingleNode("/infos/appid");
                if (xmlNode3 != null)
                {
                    model.appid = xmlNode3.InnerText.Trim();
                }
                XmlNode xmlNode4 = xdoc.SelectSingleNode("/infos/access_token");
                if (xmlNode4 != null)
                {
                    model.access_token = xmlNode4.InnerText.Trim();
                }
                return model;
            }
            catch (Exception e)
            {
                CustomMethod.WriteLog("GetJDModelByXML:"+e.Message.ToString());
                //model.access_token = "";
                //model.appid = "";
                //model.appsecret = "";
                //model.appkey = "";
                return null;
            }
        }
    }
}
